const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const cors = require("cors");

const indexRouter = require("./routes/index");
const usersRouter = require("./routes/users");
const dailyMenusRouter = require("./routes/dailyMenus");
const dishesRouter = require("./routes/dishes");
const commentsRouter = require("./routes/comments");
const dishTypesRouter = require("./routes/dishTypes");
const imageUploadRouter = require("./routes/image-upload");

const articlesRouter = require("./routes/articles");

const app = express();

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use(cors()); // 跨域
app.use("/", indexRouter);
app.use("/users", usersRouter);
app.use("/dailyMenu", dailyMenusRouter);
app.use("/dishes", dishesRouter);
app.use("/comments", commentsRouter);
app.use("/dishTypes", dishTypesRouter);
app.use("/image-upload", imageUploadRouter);

app.use("/articles", articlesRouter);

module.exports = app;
